Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Apple String Catalog Support #2893

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

feat: Apple String Catalog Support #2893

wants to merge 12 commits into from

Conversation

neo773
Copy link

@neo773 neo773 commented Feb 4, 2025

This PR adds support for Apple String Catalog Support

demo

a.mp4

/claim #2300
/closes #2300

@neo773 neo773 marked this pull request as ready for review February 4, 2025 17:25
@neo773
Copy link
Author

neo773 commented Feb 4, 2025

@JanCizmar Hi, this is ready to be reviewed

@JanCizmar
Copy link
Contributor

Impressive job! I am reviewing it now.

@JanCizmar JanCizmar self-requested a review February 5, 2025 08:50
@ftp27
Copy link

ftp27 commented Feb 5, 2025

I believe it should use the key as the original translation. Additionally, it doesn't recognize some format specifiers and eventually breaks them during export. Here is the export result. English was the original language for the file, by the way.
image

@neo773
Copy link
Author

neo773 commented Feb 5, 2025

Will look into it, thanks!

@Test
fun `returns correct parsed result`() {
processFile()
mockUtil.fileProcessorContext.assertLanguagesCount(2) // en, fr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see that by default it converts %@ and %lld parameters into the Tolgee Universal ICU format by default. Please add such params to the example files and test them.

.assertSinglePlural {
hasText(
"""
{value, plural,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we also need to test what happens when there is some ICU syntax by any chance in the string. Such syntax has to be escaped.

This is tested here:
io.tolgee.unit.formats.apple.in.StringsdictFormatProcessorTest#import with placeholder conversion (disabled ICU)

@JanCizmar
Copy link
Contributor

It also looks like the exported json is not formatted.

@JanCizmar
Copy link
Contributor

JanCizmar commented Feb 5, 2025

@ftp27 I believe you are using it wrong. You have to enable the conversion to Tolgee ICU placeholders when importing or you need to disable ICU support on the project configuration level.

It seems like you have the ICU support enabled, but you turned off the conversion when importing. This leads to escaped % sign when exporting so %@ goes to %%@.

More context here:

https://docs.tolgee.io/platform/formats/apple_strings
https://docs.tolgee.io/platform/projects_and_organizations/import#importing-placeholders
https://docs.tolgee.io/platform/translation_process/tolgee_universal_icu_placeholders

@JanCizmar
Copy link
Contributor

I have prepared PR to docs and CLI:
tolgee/documentation#841
tolgee/tolgee-cli#153

@JanCizmar
Copy link
Contributor

To make ktlint pass, you need to run ./gradlew ktlintFormat task.

@neo773
Copy link
Author

neo773 commented Feb 5, 2025

@JanCizmar
Hi,

Sorry about that, pushed new changes.

@ftp27
Copy link

ftp27 commented Feb 6, 2025

@JanCizmar, you're right. Without ICU, the translation has been imported as it was supposed to be. But there's still a problem with the default language during export. Also, the whole JSON isn't exported as Xcode saves it, so the git diff will look messy. It's fixable, though, by making a change in the exported document and re-saving the file.

@JanCizmar
Copy link
Contributor

Also, the whole JSON isn't exported as Xcode saves it

What is the difference?

@ftp27
Copy link

ftp27 commented Feb 7, 2025

@JanCizmar At first glance, the JSON files from Xcode appear to be beautified, with locale keys sorted alphabetically.

I'm not sure if it's possible to replicate the original file after import. Each translation can also have a state with values like needs_review (similar to fuzzy translation) or translated. Some strings may be marked with shouldTranslate: false and can include a comment.

@neo773
Copy link
Author

neo773 commented Feb 9, 2025

@JanCizmar
Could I get a re-review? pushed some new commits and tested successfully with a real world file with 65 keys

https://github.com/SokoloffA/radiola/blob/main/Radiola/Localizable.xcstrings

Copy link
Contributor

@JanCizmar JanCizmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

I was thinking more about the state importing and I think, we should completely remove it.

Tolgee is designed to be the source of truth, so I don't think one would ever want to import the state to Tolgee.

If they have all reviewed in he xcstrings, they can always run batch operation and make everything reviewed.

We can keep it for export, but for import, I would just ignore it, because It doesn't look to me that we would need a checkbox to enable/disable the state import and that doesn't worth the hustle.

@neo773
Copy link
Author

neo773 commented Feb 10, 2025

@JanCizmar
Removed translation state and added the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Apple String Catalog Support
4 participants